﻿using System.Net.Mail;

namespace MVCWeb.Helpers
{
    /// <summary>
    /// Mail Helper.
    /// </summary>
    public class MailHelper
    {
        public static bool SendMail(string from, string to, string cc, string bcc, string subject, string msg, MailPriority priority)
        {
            try
            {
                MailMessage message = new MailMessage();
                // CC.
                if (cc.Length > 0)
                {
                    string[] myCC = cc.Split(';');
                    foreach (string ccCopy in myCC)
                    {
                        message.CC.Add(new MailAddress(ccCopy));
                    }
                }

                // BCC.
                if (bcc.Length > 0)
                {
                    string[] myBCC = bcc.Split(';');
                    foreach (string bccHide in myBCC)
                    {
                        message.Bcc.Add(new MailAddress(bccHide));
                    }
                }

                message.From = new MailAddress(from);
                message.To.Add(new MailAddress(to));
                message.Subject = subject;
                message.Body = msg;
                message.IsBodyHtml = true;
                message.Priority = priority;

                SmtpClient smtp = new SmtpClient();
                smtp.Send(message);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
